package com.atstudent.gmall.product.controller;

import com.atstudent.gmall.common.result.Result;
import com.atstudent.gmall.product.entity.BaseTrademark;
import com.atstudent.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 品牌接口
 * @ClassName：BaseTrademarkController
 * @Dexcription 品牌接口
 * @Author 薛有朋
 * @CreatDate 2024/11/19 19:37
 **/
@RestController
@RequestMapping(value = "/admin/product/baseTrademark")
public class BaseTrademarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;

    /**
     * 获取品牌分页列表
     * @Author 薛有朋
     * @Date 2024/11/23 16:11
     **/
    @GetMapping(value = "/{page}/{limit}")
    public Result<Page> findByPage(@PathVariable(value = "page") Integer pageNum ,@PathVariable(value = "limit") Integer pageSize){
        Page page = baseTrademarkService.findByPage(pageNum,pageSize);
        return Result.ok(page);
    }

    /**
     * 添加品牌
     * @Author 薛有朋
     * @Date 2024/11/23 16:11
     **/
    @PostMapping(value = "/save")
    public Result save(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    /**
     * 根据id获取品牌数据
     * @Author 薛有朋
     * @Date 2024/11/23 16:12
     **/
    //"@PathVariable" 前端路径是用/拼接 就用此注解
    // "@RequestParam" 前端路径使用？拼接 就用此注解
    @GetMapping(value = "/get/{id}")
    public Result<BaseTrademark> getById(@PathVariable(value = "id") Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    /**
     * 修改品牌数据
     * @Author 薛有朋
     * @Date 2024/11/23 16:13
     **/
    //@RequestBody 前端传的参数是json格式的时候 实体类要用此注解标注
    @PutMapping(value = "/baseTrademark/update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    /**
     * 删除品牌数据
     * @Author 薛有朋
     * @Date 2024/11/20 21:38
     **/
    @DeleteMapping(value = "/remove/{id}")
    public Result deleteById (@PathVariable(value = "id") Long id){
        baseTrademarkService.deleteById(id);
        return Result.ok();
    }

    /**
     * 获取品牌属性列表
     * @Author 薛有朋
     * @Date 2024/11/24 22:06
     **/
    @GetMapping(value = "/getTrademarkList")
    public Result<List<BaseTrademark>> findAll(){
        List<BaseTrademark> baseTrademarkList = baseTrademarkService.list();
        return Result.ok(baseTrademarkList);
    }
}
